Page({
    data: {
        isNotify: false,
        countDay: 0,
        curDay: 0,
        today: 0,
        offsetLeft: 30,
        curHours: 0,
        // 周日 周一...
        week: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        weekEN: [],
        bookingTime: '8',
        time: [
            {
                title: '上午',
                // company: 'am',
                timeArr: [
                    { h: '8', m: '00', time: '30min', flag: false },
                    { h: '9', m: '00', time: '30min', flag: true },
                ]
            },
            {
                title: '下午',
                // company: 'pm',
                timeArr: [
                    { h: '18', m: '00', time: '30min', flag: false },
                    { h: '19', m: '00', time: '30min', flag: true },
                ]
            }
        ]
    },
    onLoad: function () {
        const { countDay, curDay, curHours } = this.getDate()
        const weekEN = this.getDay(countDay)
        this.setData({ countDay, curDay, weekEN, today: curDay, curHours, offsetLeft: curDay * 30 + 90 })
        this.setData({
            offsetLeft: curDay * 30 - 90
        })

    },
    // 设置星期
    getDay (day) {
        const weekEN = []
        const date = new Date()
        for (let i = 1; i <= day; i++) {
            date.setDate(i)
            weekEN.push(this.data.week[date.getDay()])
        }
        return weekEN
    },
    // 获取当月天数 已经当前天数
    getDate () {
        const date = new Date()
        const y = date.getFullYear()
        const m = date.getMonth() + 1
        const h = date.getHours()
        return {
            countDay: new Date(y, m, 0).getDate(),
            curDay: date.getDate(),
            curHours: h
        }
    },
    curDayHandle (e) {
        let { date } = e.currentTarget.dataset
        if (date >= this.data.today) {
            let { offsetLeft } = e.target
            this.setData({
                curDay: date,
                offsetLeft: date * 30
            })
        }
    },
    // 根据当前天数设置滚动距离
    setDayScroll (day) {


    },
    handleCancel (e) {
        // 已预约传1,未预约传0
        let { item } = e.currentTarget.dataset
        // console.log('点击取消预约')
    },
    handleClick (e) {
        // console.log(`%c✅w=> `, 'color:#ff7b54;font-size:16px;', e)
        let { item } = e.currentTarget.dataset
        let { curDay, today } = this.data
        let { curHours } = this.getDate
        if ((curHours < item.h) && (curDay == today) || (curDay != today)) {
            wx.navigateTo({ url: "/pages/exclusive-details/exclusive-details?flag=" + item.flag })
        }
    },
    noop () { },

    onReady: function () {
    },
    onShow: function () {
    },
    onHide: function () {
    },
    onUnload: function () {
    },
    onPullDownRefresh: function () {
    },
    onReachBottom: function () {
    }
})
